package com.mxx.qh;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.mxx.qh.config.ConstantsConfig;
import com.tencent.mm.opensdk.constants.ConstantsAPI;


/**
 * @ClassName: WXAuthorizeBroadCast
 * @Description: java类作用描述
 * @Author: ljf89 (刘江飞)
 * @Date: 2021/1/10-- 10:21
 * @Email: 642371742@qq.com
 */
public class WXAuthorizeBroadCast extends BroadcastReceiver {
    public static final String WX_AUTHORIZE_ACTION = "com.mxx.qian_he.WXAuthorizeBroadCast";
    private WxAuthorizeInfoListener wxAuthorizeInfoListener;

    public void setWxAuthorizeInfoListener(WxAuthorizeInfoListener wxAuthorizeInfoListener) {
        this.wxAuthorizeInfoListener = wxAuthorizeInfoListener;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            if (intent != null && intent.getExtras() != null) {
                Bundle mBundle = intent.getExtras();
                int type = (int) mBundle.getSerializable(ConstantsConfig.TYPE);
                if (type == ConstantsAPI.COMMAND_SENDAUTH) {
                    String state = (String) mBundle.getSerializable(ConstantsConfig.STATE);
                    String code = (String) mBundle.getSerializable(ConstantsConfig.CODE);
                    wxAuthorizeInfoListener.getAuthorizeInfoSuccess(state, code);
                } else {
                    String result = (String) mBundle.getSerializable(ConstantsConfig.RESULT);
                    wxAuthorizeInfoListener.getAuthorizeInfoFail(result);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            wxAuthorizeInfoListener.getAuthorizeInfoFail(e.getMessage());
        }
    }
}
